/**
 * Copyright (c) 2013-Now http://dreamcode123321.com All rights reserved.
 */
package com.jeesite.modules.ab.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.ab.entity.AbHouse;
import com.jeesite.modules.ab.service.AbHouseService;

/**
 * 住户信息Controller
 * @author dc
 * @version 2020-07-12
 */
@Controller
@RequestMapping(value = "${adminPath}/ab/abHouse")
public class AbHouseController extends BaseController {

	@Autowired
	private AbHouseService abHouseService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public AbHouse get(String houseCode, boolean isNewRecord) {
		return abHouseService.get(houseCode, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequestMapping(value = {"list", ""})
	public String list(AbHouse abHouse, Model model) {
		model.addAttribute("abHouse", abHouse);
		return "modules/ab/abHouseList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<AbHouse> listData(AbHouse abHouse, HttpServletRequest request, HttpServletResponse response) {
		abHouse.setPage(new Page<>(request, response));
		Page<AbHouse> page = abHouseService.findPage(abHouse);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequestMapping(value = "form")
	public String form(AbHouse abHouse, Model model) {
		model.addAttribute("abHouse", abHouse);
		return "modules/ab/abHouseForm";
	}

	/**
	 * 保存住户信息
	 */
	@RequiresPermissions("ab:abHouse:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated AbHouse abHouse) {
		abHouseService.save(abHouse);
		return renderResult(Global.TRUE, text("保存住户信息成功！"));
	}
	
	/**
	 * 删除住户信息
	 */
	@RequiresPermissions("ab:abHouse:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(AbHouse abHouse) {
		abHouseService.delete(abHouse);
		return renderResult(Global.TRUE, text("删除住户信息成功！"));
	}
	
}